package org.liaohailong.victorlibrary.http;

import androidx.annotation.NonNull;

import org.liaohailong.library.http.AbHttpCallback;

/**
 * Author: liaohailong
 * Date: 2022/8/12
 * Time: 21:34
 * Description:
 **/
public abstract class HttpCallback<T> extends AbHttpCallback<BaseResponse<T>> {
    @Override
    protected void onResponse(BaseResponse<T> rawData) {
        super.onResponse(rawData);

        // TODO: 处理全局性的业务逻辑
        // 403 重登录

        // 回调成功
        onSuccess(rawData.getData());
    }

    @Override
    public final void onFailure(@NonNull Exception exception) {
        super.onFailure(exception);

        onFailure(101, exception.getMessage());
    }

    protected abstract void onSuccess(T data);

    protected abstract void onFailure(int code, String error);
}
